package cn.szzsi.service;

import cn.szzsi.common.model.FavoriteProduct;
import cn.szzsi.common.model.Member;
import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Db;

import java.util.Date;

public class FavoriteProductService {

    public static final FavoriteProductService service = new FavoriteProductService();

    /**
     * 保存收藏的商品
     * @param member 用户对象
     * @param productId 产品id
     */
    public void saveInfo(Member member,String productId){
        FavoriteProduct favoriteProduct=new FavoriteProduct();
        favoriteProduct.setId(StrKit.getRandomUUID());
        favoriteProduct.setMemberId(member.getId());
        favoriteProduct.setShopId(member.getShopId());
        favoriteProduct.setProductId(productId);
        favoriteProduct.setCreateTime(new Date());
        favoriteProduct.save();
    }

    /**
     * 删除收藏对象
     * @param member
     * @param productId
     */
    public void deleteInfo(Member member,String productId){
        Db.update("delete from mall_favorite_product where memberId=? and productId=?",member.getId(),productId);
    }
}
